\pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\f0\b\i0\ulnone\fs24\fc0\cf0 bc
\b0 is an interactive processor for a language which resembles C but provides unlimited precision arithmetic. It takes input from any files given, then reads the standard input. The -l argument stands for the name of an arbitrary precision math library. The syntax for bc programs is as follows; L means letter a-z, E means expression, S means statement.\
Comments are enclosed in /* and */.\
Names simple variables: L array elements: L [ E ] The words `ibase', `obase', and `scale'\
Other operands arbitrarily long numbers with optional sign and decimal point. ( E ) sqrt ( E ) length ( E ) number of significant decimal digits scale ( E ) number of digits right of decimal point L ( E , ... , E )\
Operators + * / % ^ (% is remainder; ^ is power) ++ -(prefix and postfix; apply to names) == <= >= != < > = += -= *= /= %= ^=\
Statements E \{ S ; ... ; S \} if ( E ) S while ( E ) S for ( E ; E ; E ) S null statement break quit\
Function definitions define L ( L ,..., L ) \{ auto L, ... , L S; ... S return ( E ) \}\
Functions in -l math library s(x) sine c(x) cosine e(x) exponential l(x) log a(x) arctangent j(n,x) Bessel function\
All function arguments are passed by value.\
The value of a statement that is an expression is printed unless the main operator is an assignment. Either semicolons or newlines may separate statements. Assignment to scale influences the number of digits to be retained on arithmetic operations in the manner of dc(1). Assignments to ibase or obase set the input and output number radix respectively.\
The same letter may be used as an array, a function, and a simple variable simultaneously. All variables are global to the program. `Auto' variables are pushed down during function calls. When using arrays as function arguments or defining them as automatic variables empty square brackets must follow the array name.\
For example\
scale = 20 define e(x)\{ auto a, b, c, i, s a = 1 b = 1 s = 1 for(i=1; 1==1; i++)\{ a = a*x b = b*i c = a/b if(c == 0) return(s) s = s+c \} \}\
defines a function to compute an approximate value of the exponential function and\
for(i=1; i<=10; i++) e(i)\
prints approximate values of the exponential function of the first ten integers.\
Bc is actually a preprocessor for dc(1), which it invokes automatically, unless the -c (compile only) option is present. In this case the dc input is sent to the standard output instead.
\pard\tx533\tx1067\tx1601\tx2135\tx2668\tx3202\tx3736\tx4270\tx4803\tx5337\f0\b0\i0\ulnone\fs24\fc0\cf0 Compile only
{\rtf0\ansi{\fonttbl\f0\fmodern Courier;}
\margl40
\margr40
\pard\tx533\tx1067\tx1601\tx2135\tx2668\tx3202\tx3736\tx4270\tx4803\tx5337\f0\b0\i0\ulnone\fs24\fc0\cf0 The name of an arbitrary precision math library
CommandArgument
{\rtf0\ansi{\fonttbl\f0\fmodern Courier;}
\margl40
\margr40
\pard\tx533\tx1067\tx1601\tx2135\tx2668\tx3202\tx3736\tx4270\tx4803\tx5337\f0\b0\i0\ulnone\fs24\fc0\cf0 The input for
\pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\f0\b\i0\ulnone\fs24\fc0\cf0 dc
\b0 is an arbitrary precision arithmetic package. Ordinarily it operates on decimal integers, but one may specify an input base, output base, and a number of fractional digits to be maintained. The overall structure of dc is a stacking (reverse Polish) calculator. If an argument is given, input is taken from that file until its end, then from the standard input. The following constructions are recognized:\
number The value of the number is pushed on the stack. A number is an unbroken string of the digits 0-9. It may be preceded by an underscore _ to input a negative number. Numbers may contain decimal points.\
+ / * % ^ The top two values on the stack are added (+), subtracted (-), multiplied (*), divided (/), remaindered (%), or exponentiated (^). The two entries are popped off the stack; the result is pushed on the stack in their place. Any fractional part of an exponent is ignored.\
sx The top of the stack is popped and stored into a register named x, where x may be any character. If the s is capitalized, x is treated as a stack and the value is pushed on it.\
lx The value in register x is pushed on the stack. The register x is not altered. All registers start with zero value. If the l is capitalized, register x is treated as a stack and its top value is popped onto the main stack.\
d The top value on the stack is duplicated.\
p The top value on the stack is printed. The top value remains unchanged. P interprets the top of the stack as an ascii string, removes it, and prints it.\
f All values on the stack and in registers are printed.\
q exits the program. If executing a string, the recursion level is popped by two. If q is capitalized, the top value on the stack is popped and the string execution level is popped by that value.\
x treats the top element of the stack as a character string and executes it as a string of dc commands.\
X replaces the number on the top of the stack with its scale factor.\
[ ... ] puts the bracketed ascii string onto the top of the stack.\
<x >x =x The top two elements of the stack are popped and compared. Register x is executed if they obey the stated relation.\
v replaces the top element on the stack by its square root. Any existing fractional part of the argument is taken into account, but otherwise the scale factor is ignored.\
! interprets the rest of the line as a UNIX command.\
c All values on the stack are popped.\
i The top value on the stack is popped and used as the number radix for further input. I pushes the input base on the top of the stack.\
o The top value on the stack is popped and used as the number radix for further output.\
O pushes the output base on the top of the stack.\
k the top of the stack is popped, and that value is used as a non-negative scale factor: the appropriate number of places are printed on output, and maintained during multiplication, division, and exponentiation. The interaction of scale factor, input base, and output base will be reasonable if all are changed together.\
z The stack level is pushed onto the stack.\
Z replaces the number on the top of the stack with its length.\
? A line of input is taken from the input source (usually the terminal) and executed.\
; : are used by bc for array operations.\
An example which prints the first ten values of n! is\
\b [la1+dsa*pla10>y]sy 0sa1 lyx
{\rtf0\ansi{\fonttbl\f0\fmodern Courier;}
\margl40
\margr40
\pard\tx533\tx1067\tx1601\tx2135\tx2668\tx3202\tx3736\tx4270\tx4803\tx5337\f0\b0\i0\ulnone\fs24\fc0\cf0 The file to take arithmetic input from
\b0 takes pairs of numbers from the standard input as abcissas and ordinates of a function. It produces a similar set, which is approximately equally spaced and includes the input set, on the standard output. The cubic spline output (R. W. Hamming, Numerical Methods for Scientists and Engineers, 2nd ed., 349ff) has two continuous derivatives, and sufficiently many points to look smooth when plotted, for example by graph(1G).
\pard\tx533\tx1067\tx1601\tx2135\tx2668\tx3202\tx3736\tx4270\tx4803\tx5337\f0\b0\i0\ulnone\fs24\fc0\cf0 Supply abscissas automatically (they are missing from the input); spacing is given by the next argument, or is assumed to be 1 if next argument is not a number.
number
{\rtf0\ansi{\fonttbl\f0\fmodern Courier;}
\margl40
\margr40
\pard\tx520\tx1060\tx1600\tx2120\tx2660\tx3200\tx3720\tx4260\tx4800\tx5320\f0\b0\i0\ulnone\fs24\fc0\cf0 The number of spaces
{\rtf0\ansi{\fonttbl\f0\fmodern Courier;}
\margl40
\margr40
\pard\tx533\tx1067\tx1601\tx2135\tx2668\tx3202\tx3736\tx4270\tx4803\tx5337\f0\b0\i0\ulnone\fs24\fc0\cf0 The constant k used in the boundary value computation
{\rtf0\ansi{\fonttbl\f0\fmodern Courier;}
\margl40
\margr40
\pard\tx520\tx1060\tx1600\tx2120\tx2660\tx3200\tx3720\tx4260\tx4800\tx5320\f0\b0\i0\ulnone\fs24\fc0\cf0 The value of k
{\rtf0\ansi{\fonttbl\f0\fmodern Courier;}
\margl40
\margr40
\pard\tx533\tx1067\tx1601\tx2135\tx2668\tx3202\tx3736\tx4270\tx4803\tx5337\f0\b0\i0\ulnone\fs24\fc0\cf0 Space output points so that approximately n intervals occur between the lower and upper x limits. (Default n = 100)
{\rtf0\ansi{\fonttbl\f0\fmodern Courier;}
\margl40
\margr40
\pard\tx520\tx1060\tx1600\tx2120\tx2660\tx3200\tx3720\tx4260\tx4800\tx5320\f0\b0\i0\ulnone\fs24\fc0\cf0 The space between output points
{\rtf0\ansi{\fonttbl\f0\fmodern Courier;}
\margl40
\margr40
\pard\tx533\tx1067\tx1601\tx2135\tx2668\tx3202\tx3736\tx4270\tx4803\tx5337\f0\b0\i0\ulnone\fs24\fc0\cf0 Make output periodic, i.e. match derivatives at ends. First and last input values should normally agree
F{\rtf0\ansi{\fonttbl\f0\fmodern Courier;}
\margl40
\margr40
\pard\tx533\tx1067\tx1601\tx2135\tx2668\tx3202\tx3736\tx4270\tx4803\tx5337\f0\b0\i0\ulnone\fs24\fc0\cf0 Next 1 (or 2) arguments are lower (and upper) x limits. Normally these limits are calculated from the data. Automatic abcissas start at lower limit (default 0)
lower
{\rtf0\ansi{\fonttbl\f0\fmodern Courier;}
\margl40
\margr40
\pard\tx520\tx1060\tx1600\tx2120\tx2660\tx3200\tx3720\tx4260\tx4800\tx5320\f0\b0\i0\ulnone\fs24\fc0\cf0 The lower limit for abcissas
upper
{\rtf0\ansi{\fonttbl\f0\fmodern Courier;}
\margl40
\margr40
\pard\tx520\tx1060\tx1600\tx2120\tx2660\tx3200\tx3720\tx4260\tx4800\tx5320\f0\b0\i0\ulnone\fs24\fc0\cf0 The upper limit for abcissas
\pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\f0\b\i0\ulnone\fs24\fc0\cf0 units
\b0 converts quantities expressed in various standard scales to their equivalents in other scales. It works interactively in this fashion:\
You have: inch You want: cm * 2.54000e+00 / 3.93701e-01\
A quantity is specified as a multiplicative combination of units optionally preceded by a numeric multiplier. Powers are indicated by suffixed positive integers, division by the usual sign:\
You have: 15 pounds force/in2 You want: atm * 1.02069e+00 / 9.79730e-01\
Units only does multiplicative scale changes. Thus it can convert Kelvin to Rankine, but not Centigrade to Fahrenheit. Most familiar units, abbreviations, and metric prefixes are recognized, together with a generous leavening of exotica and a few constants of nature including:\
pi ratio of circumference to diameter c speed of light e charge on an electron g acceleration of gravity force same as g mole Avogadro's number water pressure head per unit height of water au astronomical unit\
`Pound' is a unit of mass. Compound names are run together, e.g. `lightyear'. British units that differ from their US counterparts are prefixed thus: `brgallon'. Currency is denoted `belgiumfranc', `britainpound', ...\
For a complete list of units, `cat /usr/lib/units'.